﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace project_phoenix.source
{
    class Level
    {
        // name of this level
        private string levelName;


        // the 3 basic textures for our bg/mg/fg
        //private Texture2D bgTexture;
        //private Texture2D mgTexture;
        //private Texture2D fgTexture;


        //Vector2 bg_position = new Vector2(0,0);
        //Vector2 mg_position = new Vector2(0,250);
        //Vector2 fg_position = new Vector2(0,650);

        //List<backgroundElement> backgrounds = new List<backgroundElement>();
        //List<backgroundElement> middlegrounds = new List<backgroundElement>();
        //List<backgroundElement> foregrounds = new List<backgroundElement>();


        // Every level is going to have a series of backgrounds
        private List<Texture2D> backgrounds = new List<Texture2D>();
        private List<Texture2D> middlegrounds = new List<Texture2D>();
        private List<Texture2D> foregrounds = new List<Texture2D>();

        // coords for each bg -- TODO: wrap these up in a struct / class
        private List<Vector2> backgroundPositions = new List<Vector2>();
        private List<Vector2> middlegroundPositions = new List<Vector2>();
        private List<Vector2> foregroundPositions = new List<Vector2>();



        // a list of all the "doodads"
        List<Entity> levelEntities = new List<Entity>();

        private int currentIndex = 0;

        public Level()
        {
            levelName = "test level";
        }


        public void Update(GameTime gameTime)
        {
        }

        public void UpdateSinglePlayer(PlayableEntity player)
        {
            //Console.WriteLine("Player x = " + player.Position);
        }

        public void Draw()
        {
            //spriteBatch.Draw(bgTexture, new Vector2(0,0), Color.White);
            //spriteBatch.Draw(mgTexture, new Vector2(0,250), Color.White);

            if (currentIndex == 0)
            {
                GameSystems.Graphics.DrawImage(backgrounds[currentIndex], backgroundPositions[currentIndex], Color.White);
                GameSystems.Graphics.DrawImage(backgrounds[currentIndex + 1], backgroundPositions[currentIndex + 1], Color.White);

                GameSystems.Graphics.DrawImage(middlegrounds[currentIndex], middlegroundPositions[currentIndex], Color.White);
                GameSystems.Graphics.DrawImage(middlegrounds[currentIndex + 1], middlegroundPositions[currentIndex + 1], Color.White);
            }
            else
            {
                GameSystems.Graphics.DrawImage(backgrounds[currentIndex - 1], backgroundPositions[currentIndex - 1], Color.White);
                GameSystems.Graphics.DrawImage(backgrounds[currentIndex], backgroundPositions[currentIndex], Color.White);
                GameSystems.Graphics.DrawImage(backgrounds[currentIndex + 1], backgroundPositions[currentIndex + 1], Color.White);

                GameSystems.Graphics.DrawImage(middlegrounds[currentIndex + 1], middlegroundPositions[currentIndex + 1], Color.White);
                GameSystems.Graphics.DrawImage(middlegrounds[currentIndex], middlegroundPositions[currentIndex], Color.White);
                GameSystems.Graphics.DrawImage(middlegrounds[currentIndex - 1], middlegroundPositions[currentIndex - 1], Color.White);
            }

        }

        public void LoadTestLevel(ContentManager content)
        {
            //bgTexture = content.Load<Texture2D>("bg");
            //mgTexture = content.Load<Texture2D>("mg");
            //fgTexture = content.Load<Texture2D>("fg");
            //content.Load<Texture2D>("bg");


            // Create some background stuff
            backgrounds.Add(content.Load<Texture2D>("sprites\\bg"));
            backgroundPositions.Add(new Vector2(0,0));

            backgrounds.Add(content.Load<Texture2D>("sprites\\bg"));
            backgroundPositions.Add(new Vector2(1280, 0));

            backgrounds.Add(content.Load<Texture2D>("sprites\\bg"));
            backgroundPositions.Add(new Vector2(2560, 0));



            middlegrounds.Add(content.Load<Texture2D>("sprites\\mg"));
            middlegroundPositions.Add(new Vector2(0, 250));

            middlegrounds.Add(content.Load<Texture2D>("sprites\\mg"));
            middlegroundPositions.Add(new Vector2(1280, 250));

            middlegrounds.Add(content.Load<Texture2D>("sprites\\mg"));
            middlegroundPositions.Add(new Vector2(2560, 250));

            middlegrounds.Add(content.Load<Texture2D>("sprites\\mg"));
            middlegroundPositions.Add(new Vector2(5120, 250));


            foregrounds.Add(content.Load<Texture2D>("sprites\\fg"));
            foregroundPositions.Add(new Vector2(0, 650));


            foregrounds.Add(content.Load<Texture2D>("sprites\\fg"));
            foregroundPositions.Add(new Vector2(1280, 650));


            foregrounds.Add(content.Load<Texture2D>("sprites\\fg"));
            foregroundPositions.Add(new Vector2(2560, 650));


        }

        public void DrawForeground()
        {
            //spriteBatch.Draw(fgTexture, new Vector2(0, 650), Color.White);
            GameSystems.Graphics.DrawImage(foregrounds[currentIndex], foregroundPositions[currentIndex], Color.White);
        }

        public void Load()
        {

        }

        public void LoadContent()
        {

        }
    }
}
